from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-28 14:10:50.305358
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 28, Oct, 2022
Time: 14:10:56
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.8439
Nobs: 823.000 HQIC: -51.1616
Log likelihood: 10714.3 FPE: 4.95394e-23
AIC: -51.3593 Det(Omega_mle): 4.44369e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.290415 0.051550 5.634 0.000
L1.Burgenland 0.108993 0.035101 3.105 0.002
L1.Kärnten -0.106729 0.018699 -5.708 0.000
L1.Niederösterreich 0.210870 0.073453 2.871 0.004
L1.Oberösterreich 0.102463 0.070381 1.456 0.145
L1.Salzburg 0.250041 0.037342 6.696 0.000
L1.Steiermark 0.037199 0.048902 0.761 0.447
L1.Tirol 0.107360 0.039687 2.705 0.007
L1.Vorarlberg -0.057915 0.034147 -1.696 0.090
L1.Wien 0.061570 0.062800 0.980 0.327
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063032 0.106593 0.591 0.554
L1.Burgenland -0.032819 0.072581 -0.452 0.651
L1.Kärnten 0.047595 0.038666 1.231 0.218
L1.Niederösterreich -0.173253 0.151884 -1.141 0.254
L1.Oberösterreich 0.386257 0.145533 2.654 0.008
L1.Salzburg 0.286111 0.077216 3.705 0.000
L1.Steiermark 0.104690 0.101119 1.035 0.301
L1.Tirol 0.314403 0.082064 3.831 0.000
L1.Vorarlberg 0.025625 0.070609 0.363 0.717
L1.Wien -0.015071 0.129857 -0.116 0.908
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188411 0.026456 7.122 0.000
L1.Burgenland 0.090734 0.018014 5.037 0.000
L1.Kärnten -0.008457 0.009597 -0.881 0.378
L1.Niederösterreich 0.264537 0.037698 7.017 0.000
L1.Oberösterreich 0.126079 0.036121 3.490 0.000
L1.Salzburg 0.048015 0.019165 2.505 0.012
L1.Steiermark 0.017303 0.025098 0.689 0.491
L1.Tirol 0.094819 0.020368 4.655 0.000
L1.Vorarlberg 0.059563 0.017525 3.399 0.001
L1.Wien 0.119944 0.032230 3.721 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104941 0.027135 3.867 0.000
L1.Burgenland 0.045014 0.018477 2.436 0.015
L1.Kärnten -0.016415 0.009843 -1.668 0.095
L1.Niederösterreich 0.193590 0.038665 5.007 0.000
L1.Oberösterreich 0.293952 0.037048 7.934 0.000
L1.Salzburg 0.116524 0.019657 5.928 0.000
L1.Steiermark 0.099552 0.025742 3.867 0.000
L1.Tirol 0.117800 0.020891 5.639 0.000
L1.Vorarlberg 0.070935 0.017975 3.946 0.000
L1.Wien -0.026519 0.033057 -0.802 0.422
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120286 0.049345 2.438 0.015
L1.Burgenland -0.049800 0.033599 -1.482 0.138
L1.Kärnten -0.040711 0.017899 -2.274 0.023
L1.Niederösterreich 0.169239 0.070311 2.407 0.016
L1.Oberösterreich 0.137835 0.067370 2.046 0.041
L1.Salzburg 0.284986 0.035745 7.973 0.000
L1.Steiermark 0.034086 0.046810 0.728 0.467
L1.Tirol 0.166764 0.037989 4.390 0.000
L1.Vorarlberg 0.105408 0.032687 3.225 0.001
L1.Wien 0.073666 0.060114 1.225 0.220
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055460 0.039035 1.421 0.155
L1.Burgenland 0.039814 0.026579 1.498 0.134
L1.Kärnten 0.050316 0.014160 3.553 0.000
L1.Niederösterreich 0.225183 0.055621 4.049 0.000
L1.Oberösterreich 0.283699 0.053295 5.323 0.000
L1.Salzburg 0.052257 0.028277 1.848 0.065
L1.Steiermark -0.008343 0.037030 -0.225 0.822
L1.Tirol 0.151282 0.030052 5.034 0.000
L1.Vorarlberg 0.071411 0.025858 2.762 0.006
L1.Wien 0.079697 0.047554 1.676 0.094
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171468 0.046654 3.675 0.000
L1.Burgenland -0.005182 0.031767 -0.163 0.870
L1.Kärnten -0.061467 0.016923 -3.632 0.000
L1.Niederösterreich -0.082880 0.066476 -1.247 0.212
L1.Oberösterreich 0.193007 0.063696 3.030 0.002
L1.Salzburg 0.057544 0.033796 1.703 0.089
L1.Steiermark 0.228912 0.044257 5.172 0.000
L1.Tirol 0.495785 0.035918 13.803 0.000
L1.Vorarlberg 0.050440 0.030904 1.632 0.103
L1.Wien -0.045744 0.056836 -0.805 0.421
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153232 0.053492 2.865 0.004
L1.Burgenland -0.010938 0.036423 -0.300 0.764
L1.Kärnten 0.065576 0.019404 3.380 0.001
L1.Niederösterreich 0.200697 0.076220 2.633 0.008
L1.Oberösterreich -0.059330 0.073033 -0.812 0.417
L1.Salzburg 0.218384 0.038749 5.636 0.000
L1.Steiermark 0.113991 0.050745 2.246 0.025
L1.Tirol 0.079149 0.041182 1.922 0.055
L1.Vorarlberg 0.125072 0.035434 3.530 0.000
L1.Wien 0.115835 0.065166 1.778 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350161 0.031198 11.224 0.000
L1.Burgenland 0.006396 0.021243 0.301 0.763
L1.Kärnten -0.023708 0.011317 -2.095 0.036
L1.Niederösterreich 0.224315 0.044454 5.046 0.000
L1.Oberösterreich 0.174605 0.042595 4.099 0.000
L1.Salzburg 0.047821 0.022600 2.116 0.034
L1.Steiermark -0.016289 0.029596 -0.550 0.582
L1.Tirol 0.109881 0.024019 4.575 0.000
L1.Vorarlberg 0.074229 0.020666 3.592 0.000
L1.Wien 0.053630 0.038007 1.411 0.158
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041850 0.152870 0.190429 0.159579 0.125674 0.115873 0.066570 0.227437
Kärnten 0.041850 1.000000 -0.002340 0.129865 0.042572 0.096764 0.429225 -0.052865 0.101325
Niederösterreich 0.152870 -0.002340 1.000000 0.337838 0.157173 0.300546 0.113134 0.184204 0.329552
Oberösterreich 0.190429 0.129865 0.337838 1.000000 0.234296 0.333554 0.174999 0.173729 0.264283
Salzburg 0.159579 0.042572 0.157173 0.234296 1.000000 0.148096 0.131593 0.149418 0.137416
Steiermark 0.125674 0.096764 0.300546 0.333554 0.148096 1.000000 0.154832 0.142026 0.080085
Tirol 0.115873 0.429225 0.113134 0.174999 0.131593 0.154832 1.000000 0.115930 0.157227
Vorarlberg 0.066570 -0.052865 0.184204 0.173729 0.149418 0.142026 0.115930 1.000000 0.008210
Wien 0.227437 0.101325 0.329552 0.264283 0.137416 0.080085 0.157227 0.008210 1.000000